<template>
  <div class="line">
    <headers></headers>
    
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1>精选路线</h1>
        <p>专业定制旅游路线，带您领略最美风景</p>
        <div class="search-box">
          <el-input
            v-model="search.name"
            placeholder="路线名称"
            prefix-icon="el-icon-map-location"
            clearable
            @keyup.enter.native="searchPage"
          ></el-input>
          <el-input
            v-model="search.geography"
            placeholder="地理位置"
            prefix-icon="el-icon-location"
            clearable
            @keyup.enter.native="searchPage"
          ></el-input>
          <el-input
            v-model="search.temperature"
            placeholder="气候温度"
            prefix-icon="el-icon-sunny"
            clearable
            @keyup.enter.native="searchPage"
          ></el-input>
          <el-button type="primary" @click="searchPage" icon="el-icon-search">搜索</el-button>
          <el-button @click="resetSearch" icon="el-icon-refresh">清空</el-button>
        </div>
      </div>
                </div>

    <!-- 路线列表 -->
    <div class="content-section">
      <div class="routes-grid">
        <div class="route-card" v-for="(item, index) in tableData" :key="index" @click="toInfo(item.id)">
          <div class="card-image" :style="{ backgroundImage: `url(${item.images.split(',')[0]})` }">
            <div class="card-overlay">
              <div class="view-details">
                <i class="el-icon-view"></i>
                查看详情
              </div>
            </div>
          </div>
          <div class="card-content">
            <h3>{{item.name}}</h3>
            <p class="description">{{item.introduce}}</p>
            <div class="card-info">
              <span v-if="item.geography" class="info-item">
                <i class="el-icon-location-outline"></i>
                {{item.geography}}
              </span>
              <span v-if="item.temperature" class="info-item">
                <i class="el-icon-sunny"></i>
                {{item.temperature}}
              </span>
              <span v-if="item.days" class="info-item">
                <i class="el-icon-time"></i>
                {{item.days}}天
              </span>
                </div>
            </div>
        </div>
      </div>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
            background
            :page-size="search.pageSize"
            layout="prev, pager, next"
            @current-change="handleCurrentChange"
            :total="total">
        </el-pagination>
    </div>
    </div>

    <bottoms></bottoms>
  </div>
</template>

<script>
import { getSysLinePage } from '../../api/api'
  import headers from '@/components/header'
  import bottoms from '@/components/bottom'

  export default {
  name: 'TourismLine',
  components: {
    headers,
    bottoms
  },
    data() {
    return {
        search: {
          name: "",
          geography: "",
          temperature: "",
          pageSize: 12,
          pageNumber: 1,
        },
      total: 100,
        tableData: [],
      }
    },
    methods: {
      searchPage() {
      this.search.pageNumber = 1
        this.getSysLinePage()
      },
      getSysLinePage() {
        getSysLinePage(this.search).then(res => {
          if (res.code == 1000) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },
      toInfo(id) {
        this.$router.push("/lineInfo?id=" + id)
      },
      handleCurrentChange(val) {
        this.search.pageNumber = val
        this.getSysLinePage()
      }, 
    resetSearch() {
      this.search.name = "";
      this.search.geography = "";
      this.search.temperature = "";
      this.search.pageNumber = 1;
      this.getSysLinePage();
    }
    },
    mounted() {
      this.getSysLinePage()
    }
 }
</script>

<style scoped>
.line {
  min-height: 100vh;
  background-color: #f8f9fa;
}

/* 页面头部样式 */
.page-header {
  background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
  background-size: cover;
  background-position: center;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  margin-bottom: 40px;
}

.header-content {
  max-width: 800px;
  padding: 0 20px;
}

.header-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.header-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* 搜索框样式 */
.search-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto auto;
  gap: 1rem;
  max-width: 1000px;
  margin: 0 auto;
}

.search-box .el-input {
  width: 100%;
}

.search-box .el-input__inner {
  height: 50px;
  border-radius: 25px;
  padding-left: 20px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.9);
}

.search-box .el-button {
  height: 50px;
  border-radius: 25px;
  padding: 0 30px;
}

/* 内容区域样式 */
.content-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 路线卡片网格 */
.routes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

/* 路线卡片样式 */
.route-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
  cursor: pointer;
}

.route-card:hover {
  transform: translateY(-5px);
}

.card-image {
  height: 200px;
  background-size: cover;
  background-position: center;
  position: relative;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.route-card:hover .card-overlay {
  opacity: 1;
}

.view-details {
  color: white;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.view-details i {
  font-size: 1.3rem;
}

.card-content {
  padding: 20px;
}

.card-content h3 {
  font-size: 1.25rem;
  color: #303133;
  margin-bottom: 10px;
  font-weight: 500;
}

.description {
  color: #606266;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-info {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #909399;
  font-size: 0.9rem;
}

.info-item i {
  font-size: 1.1rem;
}

/* 分页容器样式 */
.pagination-container {
  display: flex;
  justify-content: center;
  margin: 40px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    height: 400px;
  }

  .header-content h1 {
    font-size: 2rem;
  }

  .header-content p {
    font-size: 1rem;
  }

  .search-box {
    grid-template-columns: 1fr;
  }

  .routes-grid {
    grid-template-columns: 1fr;
  }
}
</style>